﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;

namespace PropertyManagement.qianfei
{
    public partial class editQianFei2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string sid = Request.QueryString["id"];
            if (!IsPostBack && sid != null && !sid.Equals(""))
            {
                BindTextBox(sid);
            }
        }

        private void BindTextBox(string sid)
        {
            int id;
            id = Int16.Parse(sid);
            string strsql = "select * from sqianfei where id=" + id;

            mydata myda = new mydata();
            MySqlDataReader dread = myda.getDataReader(strsql);

            if (dread.HasRows)
            {
                dread.Read();
                sid = dread["id"].ToString();
                txtId.Text = sid;

                txtsname.Text = dread["sname"].ToString();
                txtaddress.Text = dread["address"].ToString();
                txtstime.Text = dread["stime"].ToString();
                txtetime.Text = dread["etime"].ToString();
                txtmoney.Text = dread["money"].ToString();
                RadioButtonList1.SelectedValue = dread["sstatus"].ToString();
                txtperson.Text = dread["person"].ToString();
            }

            dread.Close();
            myda.closeAll();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string id, sname, address, stime, etime, money, status, person;

            id = txtId.Text;
            sname = txtsname.Text;
            address = txtaddress.Text;
            stime = txtstime.Text;
            etime = txtetime.Text;
            money = txtmoney.Text;
            status = RadioButtonList1.SelectedValue;
            person = txtperson.Text;

            string strsql = "update sqianfei set " +
                "sname='" + sname + "'," +
                "address='" + address + "'," +
                "stime='" + stime + "'," +
                "etime='" + etime + "'," +
                "money='" + money + "'," +
                "sstatus='" + status + "'," +
                "person='" + person + "'" +
                "where id=" + id;

            int n;
            mydata myda = new mydata();
            n = myda.execSql(strsql);
            if (n > 0)
            {
                Response.Write("<script language=javascript> alert('更新数据成功') </script>");
            }
            else
            {
                Response.Write("<script language=javascript> alert('更新数据失败') </script>");
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("editQianFei.aspx");
        }
    }
}